package user

import (
	"context"

	"api/internal/svc"
	"api/internal/types"
	"api/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetIDByEmailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetIDByEmailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetIDByEmailLogic {
	return &GetIDByEmailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetIDByEmailLogic) GetIDByEmail(req *types.EmailRequest) (resp *types.Empty, err error) {
	_, err = l.svcCtx.UserRPC.GetUserByEmail(l.ctx, &user.GetUserByEmailRequest{Email: req.Email})
	if err != nil {
		return nil, err
	}
	return &types.Empty{}, nil
}
